Programming Basics
Constructs Conditionals Branching IO Subroutines Exercise
These exercises are designed to evaluate your knowledge, comprehension and application of the programming constructs of conditional, branching, input/output and subroutine statements. A couple of the problems evaluate your analysis and synthesis of these basic programming constructs. A final problem will evaluate your evaluation ability of the basic programming constructs. It is expected that you should be able to correctly answer all or nearly all of the questions and problems presented. You should do these exercises by yourself. This exercise represents the most foundational and elementary information to be mastered by anyone involved with computer programming.
1. Identify the following construct types and statements. Each construct is of one or more types (conditional, branching/looping, input/output or subroutine) and one or more statements (If..Then, Select, For..Next, Open, Read, Procedure, Parameter Passing, Return Values, etc…)
a.
For time=4:59pm to 5:00pm, finish up work. Next
b.
Select entrée
Case Breakfast. choose pancakes
Case Lunch. choose sandwich
Case Dinner. choose steak
c.
Open a file
d.
If you are hungry Then eat Else keep working
e.
Write a sound clip to a file
f.
homework has been assigned
Loop do homework problems Until all problems are done.
g.
Read an image from a scanner
h.
While today is a workday, do work. Loop
i.
Goto Europe
j.
Close a file
k.
PowerOf2 (int base, int exponent)
…calculate power
…return power
l.
line = "Hello World"
OutputLine (String line)
…print line
2. Answer the following questions in regards to when the following statements are executed.
Int r := 2;
Int a := 1;
Loop
…For i=0 to 9
……If (i % 2 = 0)
……Then
………DrawCircle(r*(i+a));
……Else
………DrawSquare(r*(i+a));
…Next I
a := a + i;
Until (a > 100);
3. Write pseudo code using the programming constructs discussed to solve the given tasks.
a. Read a text file until end of file. For each character of data read if the character is a lower case ‘i’ then change it to an upper case ‘I’ and visa/versa. Write every character read to a new file.
b. For the numbers one to ten, calculate the value of the number multiplied by itself.
4. What are the minimal constructs needed to implement a sequential executing computer.